﻿using B.S.DataBase.MyProject.Domain.Management;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure;
using MediatR;
using MedicalPCTerminal.Read.API.Appcation.Commands.Management;

namespace MedicalPCTerminal.Read.API.Appcation.CommandHandlers.Management
{
    public class GetFollowCommandHandler : IRequestHandler<GetFollowCommand, APIResult<object>>
    {
        private readonly SqlSugarContext sqlSugar;

        public GetFollowCommandHandler(SqlSugarContext sqlSugar)
        {
            this.sqlSugar = sqlSugar;
        }

        public Task<APIResult<object>> Handle(GetFollowCommand request, CancellationToken cancellationToken)
        {
            APIResult<object> result=new APIResult<object>();
            try
            {
                var entity = sqlSugar.db.Queryable<Follow>().Where(x => x.BasicId == request.BasicId);
                if (entity.Count() > 0)
                {
                    result.Code = APIEnum.查询成功;
                    result.Msg = APIEnum.查询成功.ToString();
                    result.data = entity.ToList();
                }
                else
                {
                    result.Code = APIEnum.查询失败;
                    result.Msg = APIEnum.查询失败.ToString();
                }
                return Task.FromResult(result);

            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
